﻿using An_Im.UI;
using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using PPT = Microsoft.Office.Interop.PowerPoint;
using An_Im.Core;
using An_Im.Model;
using An_Im.PowerV;

namespace An_Im
{
    public partial class AnRibbon
    {
        private void AnRibbon_Load(object sender, RibbonUIEventArgs e)
        {
            Initializer.Initialize();
        }

        private void OpenButton_Click(object sender, RibbonControlEventArgs e)
        {
            // MessageBox.Show("此模块将在下一版本中进行大幅度改造，改造期间该模块禁止使用。请先将动画所有信息转移至收藏夹中。");
            // TaskPaneManager.ShowMainPane();
        }

        private void StormButton_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                TaskPaneManager.ShowStormPane();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
            
        }

        private void button2_Click(object sender, RibbonControlEventArgs e)
        {

            Process.Start(@"https://space.bilibili.com/225543640");
        }

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            Process.Start(@"https://space.bilibili.com/337176361");
        }


        private void button_DialogLuanchClick(object sender, RibbonControlEventArgs e)
        {
            new AnAboutUsWindow().ShowDialog();
        }

        private void RecorderButton_Click(object sender, RibbonControlEventArgs e)
        {
            TaskPaneManager.ShowRecorderPane();
        }

        private void marcoButton_Click(object sender, RibbonControlEventArgs e)
        {
            TaskPaneManager.ShowMacroPane();
        }

        private void button3_Click(object sender, RibbonControlEventArgs e)
        {
            var command = Command.CommandManager.GetCommand("以图形整理动画");
            if (command == null) return;
            command.Excute(CoreManipulator.App);
        }


        private void button5_Click(object sender, RibbonControlEventArgs e)
        {
            new AnImAutomaticWindow().Show();
        }


        private void button6_Click(object sender, RibbonControlEventArgs e)
        {
            TaskPaneManager.ShowCommandPane();
        }

        // TODO 待删除
        private void quickAccessButton1_Click(object sender, RibbonControlEventArgs e)
        {
            var sb = new StringBuilder();
            foreach (var extension in CoreManipulator.ExtensionHost.Extensions)
            {
                sb.AppendLine(extension.Name);


            }
            MessageBox.Show(sb.ToString());

        }

        private void quickAccessButton2_Click(object sender, RibbonControlEventArgs e)
        {
            Process.Start(CoreManipulator.FolderPath + "\\Extensions");
        }

        private void linkListButton_Click(object sender, RibbonControlEventArgs e)
        {
            TriggerLinkList.DelayEventInfomation[] infos = new TriggerLinkList.DelayEventInfomation[]
            {
                new TriggerLinkList.DelayEventInfomation(500,"你好"),
                new TriggerLinkList.DelayEventInfomation(1000,"世界"),
            };
            var triggerLinkList = new PowerV.TriggerLinkList(infos);

            VBAManipulator.AddComponent("链式触发器模块", triggerLinkList.CreatePowerVCode());
        }

        private void quickAccessButton3_Click(object sender, RibbonControlEventArgs e)
        {
            PowerV.PowerVFrame.LoadPowerVFrameTemplate(VBAManipulator.VBProject);
            // PopupWindowManager.AnimationRenameWindow.Show();
        }

        private void button4_Click(object sender, RibbonControlEventArgs e)
        {
            if(MessageBox.Show("默认会自动导入您上次的存档，您确定手动恢复吗？", "请谨慎操作", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                var pres = CoreManipulator.App.ActivePresentation;
                var vbproj = VBAManipulator.VBProject;
                PowerV.PowerVFrame.LoadInCustomData(pres, vbproj);
            }

            // Initializer.Initialize();
        }

        private void button7_Click(object sender, RibbonControlEventArgs e)
        {
            TaskPaneManager.ShowSliderPane();
        }

        private void button8_Click(object sender, RibbonControlEventArgs e)
        {
            PopupWindowManager.AnimationRenameWindow.Show();
        }

        private void button9_Click(object sender, RibbonControlEventArgs e)
        {

            if (MessageBox.Show("默认会自动保存您的 VBA 项目，您确定手动保存吗？", "请谨慎操作", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                var pres = CoreManipulator.App.ActivePresentation;
                var vbproj = VBAManipulator.VBProject;
                PowerV.PowerVFrame.SaveCustomData(pres, vbproj.VBComponents);
                pres.Save();
            }

       

      
        }
    }
}
